﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Security;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace OmniKitsWindowsDemo
{
    using OmniKits.Windows.Behaviors;

    using static System.Threading.Tasks.TaskEx;

    /// <summary>
    /// Interaction logic for BindableSecurePasswordDemo.xaml
    /// </summary>
    public partial class BindableSecurePasswordDemo : Window, INotifyPropertyChanged
    {
        public static BindableSecurePasswordDemo Instance { get; } = new BindableSecurePasswordDemo();

        private SecureString _SecurePassword;

        public event PropertyChangedEventHandler PropertyChanged;

        public SecureString SecurePassword
        {
            get { return _SecurePassword; }
            set
            {
                _SecurePassword = value;
                RaisePropertyChanged(nameof(SecurePassword));
            }
        }

        private void RaisePropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        public static void ShowInstance()
        {
            Instance.Show();
            Instance.Activate();
        }

        public BindableSecurePasswordDemo()
        {
            InitializeComponent();
        }

        private async void SetSecurePassword_Click(object sender, RoutedEventArgs e)
        {
            SecurePassword = new SecureString();
            Trace.WriteLine(SecurePassword?.Length);
            await Yield();
            Trace.WriteLine(SecurePassword?.Length);
        }

        private async void SetSecurePasswordNull_Click(object sender, RoutedEventArgs e)
        {
            SecurePassword = null;
            Trace.WriteLine(SecurePassword?.Length);
            await Yield();
            Trace.WriteLine(SecurePassword?.Length);
        }
    }
}
